#! python3
# -*- encoding: utf-8 -*-
'''
@File    :   detect.py
@Time    :   2020/10/30 22:37:36
@Author  :   lyc
@Version :   1.0
@Contact :   lyc0209@qq.com
'''

import cv2 as cv
import time
# import numpy as np

def decete():
    capture = cv.VideoCapture(0)  # 打开摄像头
    time.sleep(1)

    ret, frame = capture.read()  # 返回值，每一帧图像
    # frame = cv.flip(frame, 1)  # 镜像变换左右，上下1或-1

    dst = cv.medianBlur(frame, 5)  # 中值滤波
    # cv.imshow("median video", dst)

    # hsv = cv.cvtColor(dst, cv.COLOR_BGR2HSV)
    # cv.imshow("hsv", hsv)
    # lower_hsv = np.array([0, 0, 221])
    # upper_hsv = np.array([180, 30, 255])
    # extract_white = cv.inRange(hsv, lowerb=lower_hsv, upperb=upper_hsv)  # inRange API进行颜色提取
    # cv.imshow("extract_red demo", extract_white)

    canny = cv.Canny(dst, 40, 80)
    # cv.imshow('canny video', canny)

    # 霍夫变换圆检测
    circles = cv.HoughCircles(canny, cv.HOUGH_GRADIENT, 1,
                            50, param1=80, param2=30, minRadius=60, maxRadius=150)

    return True if circles is not None else False



if __name__ == "__main__":
    print(decete())